package com.booth.base.controllers;

import javax.servlet.http.HttpSession;

import com.booth.base.model.GroupsModules;
import com.booth.base.model.ModuleActions;
import com.booth.base.model.Users;
import com.booth.base.utils.ResultStatus;
/***
 * 模块具有的操作链接控制器
 * @TypeName：ModuleActionsController
 * @description：
 * @author：Administrator
 */
public class ModuleActionsController extends BaseController
{
	/***
	 * 进入模块链接页面
	 */
  public void index(){
    int id = getParaToInt("id", Integer.valueOf(0)).intValue();
    if (id > 0){
      setAttr("actions", ModuleActions.findByModulesId(id));
      setAttr("id", Integer.valueOf(id));
    }
    render("modules_action.jsp");
  }
  /***
   * 保存模块链接
   */
  public void save(){
    int modId = getParaToInt("id", Integer.valueOf(0)).intValue();
    String action_url = getPara("action_url", "");
    String[] urls = action_url.split(",");
    if (modId > 0){
      ModuleActions.deleteByModuleId(modId);
    }
    for (String url : urls){
      if (!"".trim().equals(url))
        ((ModuleActions)((ModuleActions)new ModuleActions().set("id", Integer.valueOf(modId))).set("action_url", url.trim())).save();
    }
    
    HttpSession session = getSession();
	Users user = (Users) session.getAttribute("user");
	user.setActionUrls(ModuleActions.findByGroupId(user.getInt("group_id").intValue()));
	user.setModuleIds(GroupsModules.findByGroupsId(user.getInt("group_id").intValue()));
	session.setAttribute("user", user);
    
    renderResult(ResultStatus.SUCCESS);
  }
}